﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class CreateRoomPlayerCountPage : EventManager
{
    public override void InformationSetting()
    {
        playerCount = "6";

        AddListenerToButton(confirmBtn, ConfirmBtnClick);
        AddListenerToButton(cancelBtn, CancelBtnClick);

        TimeSliderSelect(0);
    }

    public Button confirmBtn;
    public Button cancelBtn;
    public Slider playerCountSlider;
    public GameObject numGroup;

    private string playerCount;
    public void PlayerCountSliderValueChange()
    {
        int temp = Mathf.FloorToInt(playerCountSlider.value / 0.25f);
        playerCountSlider.value = temp * 0.25f;
        GetPlayerCount(temp.ToString());
        TimeSliderSelect(temp);
    }

    private void TimeSliderSelect(int num)
    {
        for (int i = 0; i < 5; i++)
        {
            if (i == num)
            {
                numGroup.transform.GetChild(i).gameObject.SetActive(true);
            }
            else
            {
                numGroup.transform.GetChild(i).gameObject.SetActive(false);
            }
        }

        for (int i = 5; i < 10; i++)
        {
            if (i == num+5)
            {
                numGroup.transform.GetChild(i).gameObject.SetActive(false);
            }
            else
            {
                numGroup.transform.GetChild(i).gameObject.SetActive(true);
            }
        }
    }

    private  void  GetPlayerCount(string str)
    {
        switch (str)
        {
            case "0":
                playerCount = "6";
                break;
            case "1":
                playerCount = "5";
                break;
            case "2":
                playerCount = "4";
                break;
            case "3":
                playerCount = "3";
                break;
            case "4":
                playerCount = "2";
                break;
        }
    }

    public void ConfirmBtnClick()
    {
        CreateRoomController.GetInstance().MaxPlayerCount = playerCount;
        CloseBtnClick();
    }

    public void CancelBtnClick()
    {
        CreateRoomPage.GetInstance().SetToggleIsOff(3);
        CloseBtnClick();
    }
}
